using System;

using Schemata.Core;

namespace Awaken.CodeGen
{
	/// <summary>
	/// Summary description for Database.
	/// </summary>
	public class Database
	{
		protected DatabaseSchema component;

		public DatabaseSchema Component
		{
			get{ return component; }
			set{ component=value; }
		}

        public string DatabaseName
        {
            get { return Component.Name; }
        }

		public Database( DatabaseSchema databaseSchema )
		{
			Component = databaseSchema;
		}

        public TableList SingleIdTables
        {
            get 
            {
                TableList list = new TableList();

                foreach (Table table in Tables)
                {
                    if (table.IdColumns.Count == 1)
                    {
                        list.Add(table);
                    }
                }
                return list;
            }
        }

        public TableList ManyToManyTables
        {
            get
            {
                TableList list = new TableList();

                foreach (Table table in Tables)
                {
                    if (table.IdColumns.Count == 2)
                    {
                        list.Add(table);
                    }
                }
                return list;
            }
        }

		public TableList Tables
		{
			get
			{
				TableList list = new TableList();

				foreach( TableSchema tableSchema in Component.Tables )
				{
					Table table = new Table( tableSchema );
					list.Add( table );
				}

				return list;				
			}
		}
	}
}
